//
//  KKPurchaseCommodityItemList.m
//  FreightAssistant
//
//  Created by Mac mini on 15/12/16.
//  Copyright © 2015年 leo. All rights reserved.
//

#import "KKPurchaseCommodityItemList.h"

@implementation KKPurchaseCommodityItemList

@end


@implementation KKPurchaseCommodityItem

- (instancetype)initWithItem:(KKCommodityItem *)item {
    
    if (item == nil) {
        return nil;
    }
    
    self = [super init];
    if (self) {
        
        _kk_commodityItem = [item copy];
        _kk_name = [item.kk_name copy];
        _kk_price = [item.kk_purchasePrice copy];
        _kk_currency = @"CNY";
        _kk_number = @1;
        _kk_amount = [_kk_price copy];
    }
    return self;
}

- (double)totalAmount {
    return _kk_amount.doubleValue * _kk_number.doubleValue;
}

- (void)updateAmountWithCurrency:(NSString *)currency {
    
    if (currency != nil) {
        _kk_currency = currency;
    }
    
    double price = [[KKExchangeRateManager defaultManager] exchangeValueFromCurrency: _kk_currency toCurrency: @"CNY" amount: [_kk_price doubleValue]];
    _kk_amount = @(price);
}

@end